package name.elftesting.vncelf;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Font;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.JWindow;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.border.Border;

/**
 * 
 * @author Xiaoping Wu
 * 
 */
public class JSplashWindowEx extends JWindow implements Runnable {
	Thread splashThread = null;
	private JProgressBar progress;

	public JSplashWindowEx() {
		try {

			Font font = new Font("", Font.PLAIN, 12);
			UIManager.put("Button.font", font);
			UIManager.put("Menu.font", font);
			UIManager.put("MenuItem.font", font);
			UIManager.put("TabbedPane.font", font);
			UIManager
					.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
		// JPanel splash = new JPanel(new BorderLayout());
		String imagePath = "/images/launch.jpg";
		ImageIcon image = new ImageIcon(this.getClass().getResource(imagePath));

		ImageJPanel splash = new ImageJPanel(image.getImage());
		splash.setLayout(new BorderLayout());
		progress = new JProgressBar(1, 100);
		progress.setStringPainted(true);
		progress.setBorderPainted(false);

		progress.setString("Program is Now Loading...");
		// progress.setBackground(Color.red);
		splash.add(progress, BorderLayout.SOUTH);
		// ImageIcon ii=new ImageIcon("images/launch.jpg");
		// splash.add(ii);
		setContentPane(splash);

		Dimension screen = getToolkit().getScreenSize();
		pack();
		setLocation((screen.width - getSize().width) / 2,
				(screen.height - getSize().height) / 2);
		String lookAndFeel = UIManager.getCrossPlatformLookAndFeelClassName();
		try {
			UIManager.setLookAndFeel(lookAndFeel);
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (UnsupportedLookAndFeelException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}


	public void update(String text,int value){
		progress.setString(text);
		progress.setValue(value);
	}

	public void run() {
		
	}
}
